package codeRandomThoughts.Test101对称二叉树;

import codeRandomThoughts.utils.TreeNode;

public class Solution {
    public boolean isSymmetric(TreeNode root) {
        return isSym(root.left, root.right);
    }

    boolean isSym(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        //此时同时为空的情况已经被上一条语句排除了
        if (left == null || right == null) {
            return false;
        }
        if (left.val == right.val && isSym(left.left, right.right) && isSym(left.right, right.left)) {
            return true;
        }
        return false;
    }
}
